/*     */ package com.zimbra.cs.client;
/*     */ 
/*     */ import com.zimbra.common.auth.ZAuthToken;
/*     */ import com.zimbra.common.httpclient.HttpClientUtil;
/*     */ import com.zimbra.common.util.ZimbraHttpConnectionManager;
/*     */ import com.zimbra.cs.client.soap.LmcSoapClientException;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintStream;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Map;
/*     */ import java.util.Map.Entry;
/*     */ import org.apache.commons.httpclient.Cookie;
/*     */ import org.apache.commons.httpclient.HttpClient;
/*     */ import org.apache.commons.httpclient.HttpState;
/*     */ import org.apache.commons.httpclient.methods.GetMethod;
/*     */ import org.apache.commons.httpclient.params.HttpClientParams;
/*     */ import org.apache.commons.httpclient.params.HttpMethodParams;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class LmcMessage
/*     */ {
/*     */   private String mID;
/*     */   private String mMsgIDHeader;
/*     */   private String mFlags;
/*     */   private long mSize;
/*     */   private String mDate;
/*     */   private String mConvID;
/*     */   private String mScore;
/*     */   private String mSubject;
/*     */   private String mFragment;
/*     */   private String mOriginalID;
/*     */   private String mFolder;
/*     */   private LmcEmailAddress[] mEmailAddrs;
/*     */   private ArrayList<LmcMimePart> mMimeParts;
/*     */   private String mContentMatched;
/*     */   private String mTag;
/*     */   private String mContent;
/*     */   private String[] mAttachmentIDs;
/*  54 */   private boolean mIsUnread = false;
/*     */   
/*     */   public LmcMessage() {
/*  57 */     this.mMimeParts = new ArrayList();
/*     */   }
/*     */   
/*  60 */   public void setFolder(String f) { this.mFolder = f; }
/*  61 */   public void setID(String i) { this.mID = i; }
/*  62 */   public void setMsgIDHeader(String h) { this.mMsgIDHeader = h; }
/*     */   
/*  64 */   public void setFlags(String f) { this.mFlags = f;
/*  65 */     this.mIsUnread = ((this.mFlags != null) && (this.mFlags.indexOf("u") >= 0)); }
/*     */   
/*  67 */   public void setSize(long s) { this.mSize = s; }
/*  68 */   public void setDate(String d) { this.mDate = d; }
/*  69 */   public void setConvID(String cid) { this.mConvID = cid; }
/*  70 */   public void setScore(String s) { this.mScore = s; }
/*  71 */   public void setOriginalID(String o) { this.mOriginalID = o; }
/*  72 */   public void setEmailAddresses(LmcEmailAddress[] e) { this.mEmailAddrs = e; }
/*  73 */   public void addMimePart(LmcMimePart m) { this.mMimeParts.add(m); }
/*  74 */   public void clearMimeParts() { this.mMimeParts.clear(); }
/*  75 */   public void setContentMatched(String c) { this.mContentMatched = c; }
/*  76 */   public void setFragment(String f) { this.mFragment = f; }
/*  77 */   public void setSubject(String s) { this.mSubject = s; }
/*  78 */   public void setTag(String t) { this.mTag = t; }
/*  79 */   public void setContent(String c) { this.mContent = c; }
/*  80 */   public void setAttachmentIDs(String[] ids) { this.mAttachmentIDs = ids; }
/*     */   
/*  82 */   public String getSubject() { return this.mSubject; }
/*  83 */   public String getFragment() { return this.mFragment; }
/*  84 */   public String getFolder() { return this.mFolder; }
/*  85 */   public String getID() { return this.mID; }
/*  86 */   public String getMsgIDHeader() { return this.mMsgIDHeader; }
/*  87 */   public String getFlags() { return this.mFlags; }
/*  88 */   public long getSize() { return this.mSize; }
/*  89 */   public String getDate() { return this.mDate; }
/*  90 */   public String getConvID() { return this.mConvID; }
/*  91 */   public String getScore() { return this.mScore; }
/*  92 */   public String getOriginalID() { return this.mOriginalID; }
/*  93 */   public String getContentMatched() { return this.mContentMatched; }
/*  94 */   public LmcEmailAddress[] getEmailAddresses() { return this.mEmailAddrs; }
/*     */   
/*  96 */   public LmcEmailAddress getFromAddress() { for (int i = 0; i < this.mEmailAddrs.length; i++)
/*  97 */       if (this.mEmailAddrs[i].getType().equals("f"))
/*  98 */         return this.mEmailAddrs[i];
/*  99 */     return null; }
/*     */   
/* 101 */   public int getNumMimeParts() { return this.mMimeParts.size(); }
/* 102 */   public LmcMimePart getMimePart(int i) { return (LmcMimePart)this.mMimeParts.get(i); }
/* 103 */   public String getTag() { return this.mTag; }
/* 104 */   public String getContent() { return this.mContent; }
/* 105 */   public String[] getAttachmentIDs() { return this.mAttachmentIDs; }
/*     */   
/*     */   public String toString() {
/* 108 */     String s = "Msg ID=\"" + this.mID + "\" folder=\"" + this.mFolder + "\" flags=\"" + this.mFlags + "\" size=\"" + this.mSize + "\" date=\"" + this.mDate + "\" convID=\"" + this.mConvID + "\" score=\"" + this.mScore + "\" origID=\"" + this.mOriginalID + "\" conMatched=\"" + this.mContentMatched + "\" fragment=\"" + this.mFragment + "\" subject=\"" + this.mSubject + "\" tag=\"" + this.mTag + "\"";
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 113 */     s = s + "\n\t" + (this.mEmailAddrs == null ? 0 : this.mEmailAddrs.length) + " email addresses";
/* 114 */     s = s + "\n\t" + this.mMimeParts.size();
/* 115 */     return s;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public byte[] downloadAttachment(String partNo, String baseURL, LmcSession session, String cookieDomain, int msTimeout)
/*     */     throws LmcSoapClientException, IOException
/*     */   {
/* 125 */     if (session == null) {
/* 126 */       System.err.println(System.currentTimeMillis() + " " + Thread.currentThread() + " LmcMessage.downloadAttachment session=null");
/*     */     }
/* 128 */     HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
/* 129 */     String url = baseURL + "?id=" + getID() + "&part=" + partNo;
/* 130 */     GetMethod get = new GetMethod(url);
/*     */     
/* 132 */     ZAuthToken zat = session.getAuthToken();
/* 133 */     Map<String, String> cookieMap = zat.cookieMap(false);
/* 134 */     if (cookieMap != null) {
/* 135 */       HttpState initialState = new HttpState();
/* 136 */       for (Map.Entry<String, String> ck : cookieMap.entrySet()) {
/* 137 */         Cookie cookie = new Cookie(cookieDomain, (String)ck.getKey(), (String)ck.getValue(), "/", -1, false);
/* 138 */         initialState.addCookie(cookie);
/*     */       }
/* 140 */       client.setState(initialState);
/* 141 */       client.getParams().setCookiePolicy("compatibility");
/*     */     }
/*     */     
/* 144 */     get.getParams().setSoTimeout(msTimeout);
/* 145 */     int statusCode = -1;
/*     */     try {
/* 147 */       statusCode = HttpClientUtil.executeMethod(client, get);
/*     */       
/*     */ 
/* 150 */       if (statusCode == 200) {
/* 151 */         return get.getResponseBody();
/*     */       }
/* 153 */       throw new LmcSoapClientException("Attachment download failed, status=" + statusCode);
/*     */     }
/*     */     catch (IOException e) {
/* 156 */       System.err.println("Attachment download failed");
/*     */       
/* 158 */       throw e;
/*     */     } finally {
/* 160 */       get.releaseConnection();
/*     */     }
/*     */   }
/*     */   
/* 164 */   public boolean isUnread() { return this.mIsUnread; }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/client/LmcMessage.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */